import { useModel } from "umi";
import { useReactive } from "ahooks";

const userSaveGatewayInfo = () => {
    const { remoteData } = useModel("global");
    const { baseInfo } = useModel("person.info");

    const state = useReactive({
        loading: false,
    });

    const saveGatewayInfo = async (values, callback) => {
        state.loading = true;
        let res = await remoteData({
            object: "base-platform-management-service",
            serviceName: "/person/gateway/save",
            params: {
                personUuid: baseInfo.uuid,
                uuid: values.uuid,
                url: values.url,
                publicKey: values.publicKey,
                usageStatus: values.usageStatus,
                verifyStatus: values.verifyStatus,
                initializationStatus: values.initializationStatus,
                deploiedDatabases: {
                    databaseDbName: values.databaseDbName,
                    databaseSchemas: values.databaseSchemas,
                    databaseVersionNo: values.databaseVersionNo,
                },
            },
        });
        res && callback && callback(res);
        state.loading = false;
    };

    return { ...state, saveGatewayInfo };
};

export default userSaveGatewayInfo;
